from .Institution import Institution
from django.db import models
from control.models.User import User
import uuid
from .GlobalTables import DepartmentType

# 部门信息
class Department(models.Model):
    uuid = models.UUIDField(primary_key = True,auto_created = True,default = uuid.uuid4,editable = False)
    name = models.CharField(verbose_name="名称", max_length=128)		                        
    zh_name = models.CharField(verbose_name="中文名", max_length=128, null=True, blank=True)
    dep_code = models.CharField(verbose_name="标识代码", max_length=64, null=True, blank=True)
    contact_number = models.CharField(verbose_name="联系电话", max_length=32, null=True, blank=True)
    email = models.EmailField(verbose_name="联系邮箱", null=True, blank=True)	
    website = models.URLField(verbose_name="官方网站", max_length=256, null=True, blank=True)
    founded_date = models.DateField(verbose_name="创立日期", null=True, blank=True)	
    description = models.TextField(verbose_name="描述", null=True, blank=True)	
    dep_type = models.ForeignKey(DepartmentType, verbose_name="所属类别", on_delete=models.CASCADE)
    institution = models.ForeignKey(Institution, verbose_name="所属机构", on_delete=models.CASCADE)
    
    is_reviewing = models.BooleanField(verbose_name="审核状态", default=False)
    
    creator = models.ForeignKey(User, verbose_name="创建者", related_name="depar_creator", on_delete=models.CASCADE)				
    create_date = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)
    last_editor = models.ForeignKey(User, verbose_name="最后编辑者", related_name="depar_last_editor", on_delete=models.CASCADE)	
    last_edit_date = models.DateTimeField(verbose_name='最后编辑时间', auto_now=True)					
    reviewer = models.ForeignKey(User, verbose_name="审核者", related_name="depar_reviewer", on_delete=models.CASCADE, null=True)
    review_date = models.DateTimeField(null=True, blank=True, verbose_name='审核时间')

    class Meta:
        ordering = ['-name', '-zh_name', '-dep_code', '-founded_date']
        verbose_name = "Department"           # 单数名称
        verbose_name_plural = "Departments"   # 复数名称

    def __str__(self):
        return self.name